:- use_package(persdb_mysql_op).

:- use_module(amos(configuration),[db_name/1,db_user/1,db_password/1,db_host/1]).
:- use_module(db(cipher),[decipher/2]).

sql_persistent_location(amosdb, db(DBName, DBUser, DBPassword, DBHost:DBPort)):-
	db_name(DBName),
	db_user(DBUser),
	db_password(CipheredDBPassword),
	decipher(CipheredDBPassword,DBPassword),
	db_host(DBHost:DBPort).

:- sql_persistent(identificationtags(string,string,string),
	          identificationtags(res_key,ditem_key,streaming),amosdb).
:- sql_persistent(requires(string,string,string),
	          requires(res_key,ditem_key,streaming),amosdb).
:- sql_persistent(uses(string,string,string),
	          uses(res_key,uses_key,description),amosdb).
:- sql_persistent(cert_status(string,string),
	          cert_status(res_key,certification_key),amosdb).
:- sql_persistent(synonyms(string,string),
	          synonyms(ditem_key,synonym),amosdb).
:- sql_persistent(generalizations(string,string),
	          generalizations(ditem_key,generalization_key),amosdb).
:- sql_persistent(translations(string,string,string),
	          translations(ditem_key,language,translation),amosdb).
:- sql_persistent(authors(string,string),
	          authors(asset_key,user_key),amosdb).
:- sql_persistent(maintainers(string,string),
	          maintainers(asset_key,user_key),amosdb).
:- sql_persistent(descriptions(string,string),
	          descriptions(asset_key,description),amosdb).

:- sql_persistent(asset(string,string,string,string,string,string,string,
	                string,string,string,string,string,string,string,
			string,string,string,string,string),
	          asset(asset_key,submittedby_key,certification_key,name,
		        homepage,downloadpage,contact,license,licenseurl,
			version,references_,constraints,freedom,creationdate,
			submissiondate,environment,cost,security,signature
		       ),amosdb).
:- sql_persistent(resource(string,string,string,int,string,string),
	          resource(resource_key,asset_key,language_key,size,
		           versionof,notes
			  ),amosdb).
:- sql_persistent(certification(string,string,string,string,string,string,string,
	                        string,string,string),
	          certification(certification_key,date,status,level,policy,
		                reference,artifact_type,artifact,verifier,comments
			       ),amosdb).
:- sql_persistent(ditem(string,string,string),
	          ditem(ditem_key,entry,definition),amosdb).
:- sql_persistent(organization(string,string),
	          organization(organization_key,name),amosdb).
:- sql_persistent(user(string,string,string),
	          user(user_key,organization_key,signature),amosdb).


% If any operation is needed when a program using this module has finished editing 
% the database, it must be done here.
update_db.
